home *** CD-ROM | disk | FTP | other *** search
-
- // Win includes
- #include "stdafx.h"
- #include "Shell.h"
- #include <comdef.h>
-
- // Hash for lang.h
- extern "C" {
- #include "HTTrackInterface.h"
- #define HTS_INTERNAL_BYTECODE
- #include "htsinthash.h"
- #undef HTS_INTERNAL_BYTECODE
- };
- #include "newlang.h"
-
- // test
- #ifndef _MBCS
- #error "MBCS/DBCS support not found"
- #endif
- #include <locale.h>
-
-
- int NewLangStrSz=1024;
- inthash NewLangStr=NULL;
- int NewLangStrKeysSz=1024;
- inthash NewLangStrKeys=NULL;
- UINT NewLangCP = CP_THREAD_ACP;
-
- void LANG_LOAD(char* limit_to) {
- CWaitCursor wait;
- //
- extern int NewLangStrSz;
- extern inthash NewLangStr;
- extern int NewLangStrKeysSz;
- extern inthash NewLangStrKeys;
- //
- int selected_lang=LANG_T(-1);
- //
- if (!limit_to) {
- LANG_DELETE();
- NewLangStr=inthash_new(NewLangStrSz);
- NewLangStrKeys=inthash_new(NewLangStrKeysSz);
- if ((NewLangStr==NULL) || (NewLangStrKeys==NULL)) {
- AfxMessageBox("Error in lang.h: not enough memory");
- } else {
- inthash_value_is_malloc(NewLangStr,1);
- inthash_value_is_malloc(NewLangStrKeys,1);
- }
- }
-
- CString app;
- CWinApp* pApp = AfxGetApp();
- if (pApp) {
- app=pApp->m_pszHelpFilePath;
- app=app.Left(app.ReverseFind('\\')+1);
- }
-
- /* Load master file (list of keys and internal keys) */
- if (!limit_to) {
- CString mname=app+"lang.def";
- if (!fexist((char*)LPCTSTR(mname)))
- mname="lang.def";
- FILE* fp=fopen(mname,"rb");
- if (fp) {
- char intkey[8192];
- char key[8192];
- while(!feof(fp)) {
- linput_cpp(fp,intkey,8000);
- linput_cpp(fp,key,8000);
- if (strnotempty(intkey) && strnotempty(key)) {
- char* test=LANGINTKEY(key);
-
- /* Increment for multiple definitions */
- if (strnotempty(test)) {
- int increment=0;
- int pos=strlen(key);
- do {
- increment++;
- sprintf(key+pos,"%d",increment);
- test=LANGINTKEY(key);
- } while (strnotempty(test));
- }
-
- if (!strnotempty(test)) { // Θviter doublons
- // conv_printf(key,key);
- int len;
- char* buff;
- len=strlen(intkey);
- buff=(char*)malloc(len+2);
- if (buff) {
- strcpybuff(buff,intkey);
- inthash_add(NewLangStrKeys,key,(long int)(char*)buff);
- }
- }
- } // if
- } // while
- fclose(fp);
- } else {
- AfxMessageBox("FATAL ERROR\r\n'lang.def' file NOT FOUND!\r\nEnsure that the installation was complete!");
- exit(0);
- }
- }
-
- /* Language Name? */
- char* hashname;
- {
- char name[256];
- sprintf(name,"LANGUAGE_%d",selected_lang+1);
- hashname=LANGINTKEY(name);
- }
-
- /* Get only language name */
- if (limit_to) {
- if (hashname)
- strcpybuff(limit_to,hashname);
- else
- strcpybuff(limit_to,"???");
- return;
- }
-
- /* Error */
- if (!hashname)
- return;
-
- // xxc TEST
- /*
- setlocale( LC_ALL, "Japanese");
- _setmbcp(932); // shift-jis
- setlocale( LC_ALL, ".932" );
- setlocale( LC_ALL, "[.932]" );
- CString st="";
- int lid=SetThreadLocale(MAKELCID(MAKELANGID(LANG_JAPANESE,SUBLANG_NEUTRAL),SORT_DEFAULT ));
- */
-
- /* Load specific language file */
- {
- int loops;
- CString err_msg="";
- // 2nd loop: load undefined strings
- for(loops=0;loops<2;loops++) {
- CString lbasename;
-
- {
- char name[256];
- sprintf(name,"LANGUAGE_%d",(loops==0)?(selected_lang+1):1);
- hashname=LANGINTKEY(name);
- }
- lbasename.Format("lang/%s.txt",hashname);
- CString lname=app+lbasename;
- if (!fexist((char*)LPCTSTR(lname)))
- lname=lbasename;
- FILE* fp=fopen(lname,"rb");
- if (fp) {
- char extkey[8192];
- TCHAR value[8192];
- while(!feof(fp)) {
- //int ssz;
- linput_cpp(fp,extkey,8000);
- linput_cpp(fp,value,8000);
- /*
- ssz=linput_cpp(fp,value,8000);
- CString st=value;
- AfxMessageBox(st);
- if (ssz>0) {
- int tst=0;
- int test=IsTextUnicode(value,ssz,&tst);
- unsigned short st2[1024];
- int ret=MultiByteToWideChar(CP_UTF8,0,(char*)value,ssz,st2,1024);
- if (ret>0) {
- char st3[1024]="";
- int ret2=WideCharToMultiByte(CP_THREAD_ACP,0,st2,ret,(char*)st3,1024,NULL,FALSE);
- if (ret2>0) {
- AfxMessageBox(st3);
- }
- }
- }
- */
-
- if (strnotempty(extkey) && strnotempty(value)) {
- int len;
- char* buff;
- char* intkey;
-
- intkey=LANGINTKEY(extkey);
-
- if (strnotempty(intkey)) {
-
- /* Increment for multiple definitions */
- {
- char* test=LANGSEL(intkey);
- if (strnotempty(test)) {
- if (loops == 0) {
- int increment=0;
- int pos=strlen(extkey);
- do {
- increment++;
- sprintf(extkey+pos,"%d",increment);
- intkey=LANGINTKEY(extkey);
- if (strnotempty(intkey))
- test=LANGSEL(intkey);
- else
- test="";
- } while (strnotempty(test));
- } else
- intkey="";
- } else {
- if (loops > 0) {
- err_msg += intkey;
- err_msg += " ";
- }
- }
- }
-
- /* Add key */
- if (strnotempty(intkey)) {
- len=strlen(value);
- buff=(char*)malloc(len+2);
- if (buff) {
- conv_printf(value,buff);
- inthash_add(NewLangStr,intkey,(long int)(char*)buff);
- }
- }
-
- }
- } // if
- } // while
- fclose(fp);
- } else {
- AfxMessageBox("FATAL ERROR\r\n'lang.def' file NOT FOUND!\r\nEnsure that the installation was complete!");
- exit(0);
- }
- }
- if (err_msg.GetLength()>0) {
- // AfxMessageBox("Error: undefined strings follows:\r\n"+err_msg);
- }
- }
-
-
-
- #if 0
- app=app+"lang.h";
- if (!fexist((char*)LPCTSTR(app)))
- app="lang.h";
-
- FILE* fp=fopen(app,"rb");
- if (fp) {
- char s[8192];
- while(!feof(fp)) {
- linput_cpp(fp,s,8000);
- if (!strncmp(s,"#define ",8)) {
- char* a;
- char* name=s+8;
- a=name;
- while((*a!=' ') && (*a)) a++;
- if ((*a) && (strlen(name)>0) && (((int) a - (int) name)<64)) {
- *a++='\0';
- if (limit_to) {
- if (strcmp(name,limit_to))
- a=NULL;
- }
- if (a) {
- char* data;
- data=a;
- int toggle=0;
- char* start_str=NULL;
- int count=0;
- while(*a) {
- if (*a=='\"') {
- toggle++;
- if ((toggle%2)==1) {
- if (count==selected_lang) {
- start_str=a+1;
- }
- count++;
- } else {
- if (start_str) {
- char* buff;
- int len;
- len=(int) a - (int) start_str;
- if (len) {
- buff=(char*)malloc(len+2);
- if (buff) {
- int i=0,j=0;
- buff[0]='\0';
- //strncatbuff(buff,start_str,len);
- while(i<len) {
- switch(start_str[i]) {
- case '\\':
- i++;
- switch(start_str[i]) {
- case 'a': buff[j]='\a'; break;
- case 'b': buff[j]='\b'; break;
- case 'f': buff[j]='\f'; break;
- case 'n': buff[j]='\n'; break;
- case 'r': buff[j]='\r'; break;
- case 't': buff[j]='\t'; break;
- case 'v': buff[j]='\v'; break;
- case '\'': buff[j]='\''; break;
- case '\"': buff[j]='\"'; break;
- case '\\': buff[j]='\\'; break;
- case '?': buff[j]='\?'; break;
- default: buff[j]=start_str[i]; break;
- }
- break;
- default:
- buff[j]=start_str[i];
- break;
- }
- i++;
- j++;
- }
- buff[j++]='\0';
- if (!limit_to)
- inthash_add(NewLangStr,name,(long int)(char*)buff);
- else {
- strcpybuff(limit_to,buff);
- free(buff);
- return;
- }
- }
- }
- start_str=NULL;
- }
- }
- }
- a++;
- }
- }
-
- //NewLangStr.SetAt(sname,st);
- /*
- } else {
- CString info;
- info.Format("Error in lang.h: %s",name);
- AfxMessageBox(info);
- */
- }
- }
- }
-
-
- fclose(fp);
-
- } else {
- AfxMessageBox("FATAL ERROR\r\n'lang.h' file NOT FOUND!\r\nEnsure that the installation was complete!");
- exit(0);
- }
- #endif
-
- // Control limit_to
- if (limit_to)
- limit_to[0]='\0';
-
- // Set locale
- if (!limit_to) {
- CString charset = LANGUAGE_CHARSET;
- charset.TrimLeft();
- charset.TrimRight();
- charset.MakeLower();
- NewLangCP = CP_THREAD_ACP;
- #if 0
- if (charset.GetLength() > 0) {
- if (charset.Left(9) == "iso-8859-") {
- int iso = 0;
- int isoCP[] = {0, /* 0 */
- 1252, /* ISO-8859-1 */
- 1250, /* ISO-8859-2 */
- 0, /* ISO-8859-3 */
- 0, /* ISO-8859-4 */
- 1251, /* ISO-8859-5 */
- 1256, /* ISO-8859-6 */
- 1253, /* ISO-8859-7 */
- 1255, /* ISO-8859-8 */
- 1254, /* ISO-8859-9 */
- };
- if (sscanf(charset.GetBuffer(0) + 9, "%d", &iso) == 1) {
- if (iso < sizeof(isoCP)/sizeof(isoCP[0])) {
- if (isoCP[iso] != 0) {
- NewLangCP = isoCP[iso];
- }
- }
- }
- } else if (charset.Left(8) == "windows-") {
- int windows = 0;
- if (sscanf(charset.GetBuffer(0) + 8, "%d", &windows) == 1) {
- NewLangCP = windows;
- }
- } else if (charset == "shift-jis") {
- NewLangCP = 932;
- } else if (charset == "big5") {
- NewLangCP = 950;
- } else if (charset == "gb2312") {
- NewLangCP = 936;
- } else {
- NewLangCP = CP_THREAD_ACP;
- }
- }
- #endif
- }
-
- }
-
- void conv_printf(char* from,char* to) {
- int i=0,j=0,len;
- len=strlen(from);
- while(i<len) {
- switch(from[i]) {
- case '\\':
- i++;
- switch(from[i]) {
- case 'a': to[j]='\a'; break;
- case 'b': to[j]='\b'; break;
- case 'f': to[j]='\f'; break;
- case 'n': to[j]='\n'; break;
- case 'r': to[j]='\r'; break;
- case 't': to[j]='\t'; break;
- case 'v': to[j]='\v'; break;
- case '\'': to[j]='\''; break;
- case '\"': to[j]='\"'; break;
- case '\\': to[j]='\\'; break;
- case '?': to[j]='\?'; break;
- default: to[j]=from[i]; break;
- }
- break;
- default:
- to[j]=from[i];
- break;
- }
- i++;
- j++;
- }
- to[j++]='\0';
- }
-
- void LANG_DELETE() {
- extern int NewLangStrSz;
- extern inthash NewLangStr;
- extern int NewLangStrKeysSz;
- extern inthash NewLangStrKeys;
- //
- inthash_delete(&NewLangStr);
- inthash_delete(&NewLangStrKeys);
- }
-
- // sΘlection de la langue
- void LANG_INIT() {
- CWinApp* pApp = AfxGetApp();
- if (pApp) {
- int test = pApp->GetProfileInt("Language","IntId",0);
- LANG_T(pApp->GetProfileInt("Language","IntId",0));
- }
- }
-
- int LANG_T(int l) {
- if (l>=0) {
- QLANG_T(l);
- CWinApp* pApp = AfxGetApp();
- if (pApp)
- pApp->WriteProfileInt("Language","IntId",l);
- LANG_LOAD(NULL);
- }
- return QLANG_T(-1); // 0=default (english)
- }
-
- int QLANG_T(int l) {
- static int lng=0;
- if (l>=0) {
- lng=l;
- }
- return lng; // 0=default (english)
- }
-
-
- /*
- char* LANGSEL(char* lang0,...) {
- char* lang=lang0;
- char* langalt="";
- int langid=LANG_T(-1);
- //
- va_list argList;
- va_start(argList, lang0);
- while(langid>0) {
- if (lang) {
- if (strlen(langalt)==0) {
- if (strlen(lang)>0)
- langalt=lang;
- }
- }
- langid--;
- lang=va_arg(argList, char*);
- }
- va_end(argList);
- //
- if (!lang)
- return langalt;
- if (strlen(lang)==0)
- return langalt;
- return lang;
- }
- */
-
- char* LANGSEL(char* name) {
- unsigned long int adr=NULL;
- if (NewLangStr)
- if (!inthash_read(NewLangStr,name,(long int *)&adr))
- adr=NULL;
- if (adr) {
- return (char*)adr;
- }
- return "";
- }
-
- char* LANGINTKEY(char* name) {
- unsigned long int adr=NULL;
- if (NewLangStrKeys)
- if (!inthash_read(NewLangStrKeys,name,(long int *)&adr))
- adr=NULL;
- if (adr) {
- return (char*)adr;
- }
- return "";
- }
-
- static _bstr_t ConvertCodepage(LPCSTR str, UINT codePage)
- {
- _bstr_t returnValue;
- BOOL ok = TRUE;
- int mbLength = strlen(str);
- int wideLength = ::MultiByteToWideChar( codePage, 0, str, mbLength, NULL, NULL);
- if (wideLength > 0)
- {
- wchar_t *wcharBuffer = new wchar_t[wideLength+1];
- ::MultiByteToWideChar( codePage, 0, str, mbLength, wcharBuffer, wideLength);
- wcharBuffer[wideLength] = '\0';
- returnValue = wcharBuffer;
- delete wcharBuffer;
- }
- return returnValue;
- }
-
- BOOL SetDlgItemTextCP(HWND hDlg, int nIDDlgItem, LPCSTR lpString) {
- if (NewLangCP != CP_THREAD_ACP)
- return SetDlgItemTextW(hDlg, nIDDlgItem, ConvertCodepage(lpString, NewLangCP));
- else
- return SetDlgItemTextA(hDlg, nIDDlgItem, lpString);
- }
-
- BOOL SetDlgItemTextCP(CWnd* wnd, int nIDDlgItem, LPCSTR lpString) {
- return SetDlgItemTextCP(wnd->m_hWnd, nIDDlgItem, lpString);
- }
-
- BOOL SetWindowTextCP(HWND hWnd, LPCSTR lpString) {
- if (NewLangCP != CP_THREAD_ACP)
- return SetWindowTextW(hWnd, ConvertCodepage(lpString, NewLangCP));
- else
- return SetWindowTextA(hWnd, lpString);
- }
-
- BOOL SetWindowTextCP(CWnd* wnd, LPCSTR lpString) {
- return SetWindowTextCP(wnd->m_hWnd, lpString);
- }
-
- BOOL ModifyMenuCP(HMENU hMnu, UINT uPosition, UINT uFlags, UINT uIDNewItem, LPCSTR lpNewItem) {
- if (NewLangCP != CP_THREAD_ACP)
- return ModifyMenuW(hMnu, uPosition, uFlags, uIDNewItem, ConvertCodepage(lpNewItem, NewLangCP));
- else
- return ModifyMenuA(hMnu, uPosition, uFlags, uIDNewItem, lpNewItem);
- }
-
- BOOL ModifyMenuCP(CMenu* menu, UINT uPosition, UINT uFlags, UINT uIDNewItem, LPCSTR lpNewItem) {
- return ModifyMenuCP(menu->m_hMenu, uPosition, uFlags, uIDNewItem, lpNewItem);
- }
-